package cn.huas.dao.serviceImp;
/**
 * 信计团队
 * @version 1.0
 * 网址：http://www.huas.cn
 * E-mail：xieqingcheng@126.com ; txws1010@163.com
 * Copyright 2011 Hunan University of Arts and Science
 */
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import cn.huas.dao.RecordDAO;
import cn.huas.dao.service.RecordManager;
import cn.huas.model.Admin;
import cn.huas.model.Classes;
import cn.huas.model.Classroom;
import cn.huas.model.Course;
import cn.huas.model.CourseRClass;
import cn.huas.model.Professional;
import cn.huas.model.Schedule;
import cn.huas.model.Systems;
import cn.huas.model.Teachers;
import cn.huas.model.TeachersRCourse;
import cn.huas.model.Teachingbuilding;
import cn.huas.modelVo.ArgsFlag;
import cn.huas.modelVo.JAll;
import cn.huas.modelVo.ScheduleByClass;
public class RecordManagerImpl implements RecordManager{

	private RecordDAO recordDAO;
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#getRecordDAO()
	 */
	public RecordDAO getRecordDAO() {
		return recordDAO;
	}
  
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#setRecordDAO(cn.huas.dao.recordDAO)
	 */
	public void setRecordDAO(RecordDAO recordDAO) {
		this.recordDAO = recordDAO; 
	}
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#deleteProfessional(java.lang.String)
	 */
	public Boolean deleteProfessional(String ids) throws Exception {
		return recordDAO.deleteProfessional(ids);
	}
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#deleteClasses(java.lang.String)
	 */
	public Boolean deleteClasses(String ids) throws Exception {
		return  recordDAO.deleteClasses(ids);
	}

	public Boolean deleteAdmin(String ids) {
		return  recordDAO.deleteAdmin(ids);
	}
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#deleteSystems(java.lang.String)
	 */
	public Boolean deleteSystems(String ids) throws Exception {
		return recordDAO.deleteSystems(ids);
	}
	
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#deleteTeachers(java.lang.String)
	 */
	public Boolean deleteTeachers(String ids) throws Exception {
		return  recordDAO.deleteTeachers(ids);
	}

	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#deleteTeachingbuilding(java.lang.String)
	 */
	public Boolean deleteTeachingbuilding(String ids) {
		return recordDAO.deleteTeachingbuilding(ids);
	}
	
	public Boolean deleteClassroom(String ids) throws Exception {
		Boolean falg = true;
		try{
			falg = recordDAO.deleteClassroom(ids);
		}catch(Exception e){
			e.printStackTrace();
			falg=false;
		}
		return falg;
	}
	
	
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#addClasses(cn.huas.model.Classes)
	 */
	public boolean addClasses(Classes classes) throws Exception {
		return recordDAO.addClasses(classes);
	}

	public boolean addAdmin(Admin admin) throws Exception {
		return recordDAO.addAdmin(admin);
	}	
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#addSystems(cn.huas.model.Systems)
	 */
	public boolean addSystems(Systems s) throws Exception {
		return recordDAO.addSystems(s);
	}

	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#addTeachers(cn.huas.model.Teachers)
	 */
	public boolean addTeachers(Teachers teachers) throws Exception {
		return recordDAO.addTeachers(teachers);
	}
 
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#addTeachingbuilding(cn.huas.model.Teachingbuilding)
	 */
	public boolean addTeachingbuilding(Teachingbuilding t)throws Exception {
		return recordDAO.addTeachingbuilding(t);
	}

	
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#addClassroom(cn.huas.model.Classroom)
	 */
	public boolean addClassroom(Classroom classroom) throws Exception {
		return recordDAO.addClassroom(classroom);
	}

	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#addProfessional(cn.huas.model.Professional)
	 */
	public boolean addProfessional(Professional p) throws Exception {
		return recordDAO.addProfessional(p);
	}

	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#queryClassroom(cn.huas.modelVo.ArgsFlag)
	 */
	public List<Classroom> queryClassroom(ArgsFlag args) throws Exception {
		List<Classroom> list = recordDAO.queryClassroom(args);
		return list;
	}

	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#queryTeachingbuilding(cn.huas.modelVo.ArgsFlag)
	 */
	public List<Teachingbuilding> queryTeachingbuilding(ArgsFlag args) {
		List<Teachingbuilding> list = recordDAO.queryTeachingbuilding(args);
		return list;
	}

	public List<Admin> queryAdmin(ArgsFlag args) {
		List<Admin> list = recordDAO.queryAdmin(args); 
		return list;
	}
	
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#queryProfessional(cn.huas.modelVo.ArgsFlag)
	 */
	public List<Professional> queryProfessional(ArgsFlag args) throws Exception {
		return recordDAO.queryProfessional(args);
	}

	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#querySystems(cn.huas.modelVo.ArgsFlag)
	 */
	public List<Systems> querySystems(ArgsFlag args) throws Exception {
		return recordDAO.querySystems(args);
	
	}

	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#queryClasses(cn.huas.modelVo.ArgsFlag)
	 */
	public List<Classes> queryClasses(ArgsFlag args) throws Exception {
		return recordDAO.queryClasses(args);
	}
	
	/* (non-Javadoc)
	 * @see cn.huas.dao.serviceImp.d#queryTeachers(cn.huas.modelVo.ArgsFlag)
	 */
	public List<Teachers> queryTeachers(ArgsFlag argsFlag) throws Exception {
		return recordDAO.queryTeachers(argsFlag);
	}



	public boolean loginAdmin(Admin admin) throws Exception {
		return recordDAO.loginAdmin(admin);
	}


	public boolean loginTeachers(Teachers teachers) throws Exception {
		return recordDAO.loginTeachers(teachers);
	}

	public boolean loginClasses(Classes classes) throws Exception {
		return recordDAO.loginClasses(classes);
	}
	
	//排课
	public boolean paike() throws Exception{
		return recordDAO.paike();
	}

	public List<JAll> querySchedule(ArgsFlag argsFlag) throws Exception {
		List<JAll> listJAll =new ArrayList<JAll>();
		try{
			List<Schedule> listSchedule = recordDAO.querySchedule(argsFlag);
			for(Schedule schedule:listSchedule){
				Classes classes = (Classes) recordDAO.hibernateTemplate.get(Classes.class, schedule.getClass_id());
				Classroom classroom = (Classroom)recordDAO.hibernateTemplate.get(Classroom.class,schedule.getClassroom_id());
				Course course = (Course) recordDAO.hibernateTemplate.get(Course.class,schedule.getCourse_id());
				Teachers teacher = (Teachers) recordDAO.hibernateTemplate.get(Teachers.class,schedule.getTeacher_id());
				JAll jAll = new JAll();
				
				Double d = Double.valueOf(course.getCourse_totaltime())/Double.valueOf(String.valueOf(schedule.getWeek_times()));
				Double dd = Math.ceil(d);
				DecimalFormat df=new DecimalFormat("#");
				System.out.println(df.format(dd));
				
				jAll.setClassId(classes.getClasses_id());
				jAll.setClassName(classes.getClasses_name());
				jAll.setClassroomId(classroom.getId());
				jAll.setClassroomName(classroom.getTeachingbuilding().getTeachingbuilding_name()+"-"+classroom.getName());
				jAll.setCourseId(course.getCourse_id());
				jAll.setCourseName(course.getCourse_name());
				jAll.setClassId(teacher.getTeachers_id());
				jAll.setTeacherName(teacher.getTeachers_name());
				jAll.setScheduleId(schedule.getSchedule_id());
				jAll.setTotalTime(course.getCourse_totaltime());
				jAll.setWeekTime(String.valueOf(schedule.getWeek_times()));
				jAll.setWeeks(df.format(dd));
				listJAll.add(jAll);
			}
			return listJAll;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 删除教学计划
	 */
	public Boolean deleteSchedule(String ids) {
		return recordDAO.deleteSchedule(ids);
	}

	public List<ScheduleByClass> queryPaikeByClassId(ArgsFlag argsFlag) throws Exception {
		try{
			List<ScheduleByClass> listpaike = new ArrayList();
			listpaike = recordDAO.queryPaikeByClassId(argsFlag);
			return listpaike;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
		
		
	}

	public List queryPaikeByClassroomId(ArgsFlag argsFlag) throws Exception {
		try{
			List<ScheduleByClass> listpaike = new ArrayList();
			listpaike = recordDAO.queryPaikeByClassroomId(argsFlag);
			return listpaike;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	public List queryPaikeByTeacherId(ArgsFlag argsFlag) throws Exception {
		try{
			List<ScheduleByClass> listpaike = new ArrayList();
			listpaike = recordDAO.queryPaikeByTeacherId(argsFlag);
			return listpaike;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	public boolean addPaiKe(Map map) throws Exception {
		boolean falg = false;
		falg = recordDAO.addPaiKe(map);
 		return falg;
	}

	public boolean deletePaiKe(Map map) throws Exception {
		boolean falg = false;
		falg = recordDAO.deletePaiKe(map);
 		return falg;
	}

	public String queryPaiKe(Map map) throws Exception {
		String falg = recordDAO.queryPaiKe(map);
 		return falg;
	}
	
	/**
	 *  查询课程-班级关联表
	 *  @author xie
	 *  @return List<CourseRClass>
	 *  @param ArgsFlag argsFlag
	 */
	public List<CourseRClass> queryCourseRClass(ArgsFlag argsFlag){
		try{
			List<CourseRClass> list = recordDAO.queryCourseRClass(argsFlag);
			return list;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	

	
	public boolean addToTeachersRCourse(String course_ids,String ids) {
		Boolean flag = false;
		try{
			flag=recordDAO.addToTeachersRCourse(course_ids,ids);
		}catch(Exception e){
			e.printStackTrace();
			flag = false;
		}
		return flag;
	}

	/**
	 *  通过课程id__查询教师-课程关联表
	 *  @return List<TeachersRCourse>
	 *  @param ArgsFlag argsFlag
	 */
	public List<TeachersRCourse> queryTeachersRCourse(ArgsFlag args){
		List<TeachersRCourse> list = new ArrayList<TeachersRCourse>();
		try{
			list = recordDAO.queryTeachersRCourse(args);
			return list;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	/**
	 *  查询课程-老师关联表
	 *  @author xie
	 *  @return List<CourseRClass>
	 *  @param ArgsFlag argsFlag
	 */
	public List<TeachersRCourse> queryTeacherRCourse(ArgsFlag argsFlag){
		try{
			List<TeachersRCourse> list = recordDAO.queryTeacherRCourse(argsFlag);
			return list;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}


	public boolean addToCourseRClass(String courseIds, String classesIds) {
		Boolean flag = false;
		try{
			flag=recordDAO.addToCourseRClass(courseIds,classesIds);
		}catch(Exception e){
			e.printStackTrace();
			flag = false;
		}
		return flag;
	}

	@Override
	public Boolean deleteCourse(String ids) throws Exception {

		Boolean falg = true;
		try{
			falg = recordDAO.deleteCourse(ids);
		}catch(Exception e){
			e.printStackTrace();
			falg=false;
		}
		return falg;
	
	}
	public List<Course> queryCourse(ArgsFlag args) throws Exception {
		return recordDAO.queryCourse(args);
	}
	
	public boolean addCourse(Course c) throws Exception {
		return recordDAO.addCourse(c);
	}

	public boolean scheduleJihua() throws Exception{
		return recordDAO.scheduleJihua();
	}
	@Override
	public boolean delFromTeachersRCourse(String teachersIds, String courseIds) {
		return recordDAO.delFromTeachersRCourse(teachersIds,courseIds);
	}
	@Override
	public boolean delFromCourseRClass(String classesIds, String courseIds) {
		return recordDAO.delFromCourseRClass(classesIds,courseIds);
	}
	@Override
	public boolean addSchedule(ArgsFlag argsFlag) throws Exception {
		return recordDAO.addSchedule(argsFlag);
	}
}
